<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul,
        li {
            list-style: none;
        }
    </style>
</head>

<body>
    <div id="app">

        <input type="text" name="" id="" v-model="newhero" placeholder="请写英雄">
        <button @click="add">添加英雄</button>
        <ul>
            <li v-for="(item,index) in hero" :key="index"> {{index+1}} - {{item}}
                <span @click="del(index)">x</span>
            </li>
        </ul>
    </div>
    <script src="./js/vue.js"></script>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                hero: ["马可波罗", "李白", "韩信"],
                newhero: "",
            },
            methods: {
                add() {
                    this.hero.push(this.newhero)
                },
                del(index) {
                    this.hero.splice(index, 1);
                }
            }
        })
    </script>
</body>

</html>